{extend name='template/base'}{/extend}
{block name='style'}{/block}
{block name='script'}{/block}
{block name='content'}
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-body">
                <div id="toolbar">
                    <div class="btn-group pull-left mr10">
                        <a class="btn btn-primary" id="add_btn"><i class="fa fa-plus"></i> 新增规格</a>
                    </div>
                </div>
                <table id="table"
                       data-toggle="table"
                       data-striped="true"
                       data-toolbar="#toolbar"
                       data-search="true"
                       data-show-refresh="true"
                       data-query-params="requestParam"
                       data-show-toggle="true"
                       data-show-columns="true"
                       data-show-export="true"
                       data-side-pagination="server"
                       data-pagination="true"
                       data-id-field="id"
                       data-url="{$index_data_url}"
                >
                    <thead>
                    <tr>
                        <th data-field="name">规格名称</th>
                        <th data-field="price">价格</th>
                        <th data-field="sort">排序</th>
                        <th data-field="operate" data-formatter="formatOperate" data-events="operateEvents">操作</th>
                    </tr>
                    </thead>
                </table>
            </div><!-- /.box-body -->
        </div><!-- /.box -->

    </div><!-- /.col -->
</div><!-- /.row -->
{/block}
{block name='script_extra'}
<script>
    var edit_data_url = "{:url('ShopGoodsVariant/edit')}";
    var delete_data_url = "{:url('ShopGoodsVariant/delete')}";
    var goods_id = "{$goods_id}";
    console.log(goods_id);

    // <editor-fold defaultstate="collapsed" desc="格式化url">
    function urlFormat(url) {
        if (url.indexOf('.html')) {
            url = url.replace('.html', '')
        }
        return url;
    }
    // </editor-fold>


    $("#sel_status").on('change', function () {
        $('#table').bootstrapTable('refresh');
    })

    $("#sel_type").on('change', function () {
        $('#table').bootstrapTable('refresh');
    })

    //搜索按钮事件
    $("#btn_search").on('click', function () {
        $('#table').bootstrapTable('refresh');
    })


    var temp = {};
    function requestParam(params) {
        temp = {
            limit: params.limit, //页面大小
            offset: params.offset, //页码
            order: params.order,
            sort: params.sort,
            search: params.search,
            islicense: -1,
            status: $("#sel_status").val(),
            type: $("#sel_type").val(),
            begindate: $("#begindate").val(),
            enddate: $("#enddate").val()
        };
        return temp;
    }


    // <editor-fold defaultstate="collapsed" desc="添加">
    $('#add_btn').on('click', function () {
        layer_open('添加',  "{$add_url}");
    });
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="操作按钮">
    function formatOperate(value, row, index) {
        return [
            '<button class="btn btn-success btn-xs row_edit" href="javascript:void(0)">',
            '<i class="fa fa-edit"></i> 修改',
            '</button>&nbsp;',
            '<button class="btn btn-danger btn-xs row_delete" href="javascript:void(0)">',
            '<i class="fa fa-trash"></i> 删除',
            '</button>'
        ].join('');
    }

    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="操作函数">
    window.operateEvents = {
        'click .row_edit': function (e, value, row, index) {
            layer_open('更改信息', urlFormat(edit_data_url) + "/id/" + row.id );
        },
        'click .row_delete': function (e, value, row, index) {
            layer.confirm('你确定要删除该选项吗？', {btn: ['确定', '取消']}, function () {
                $.ajax({
                    dataType: 'json',
                    data: {id: row.id},
                    url: delete_data_url,
                    success: function (res) {
                        if (res.success) {
                            layer.msg(res.message, {time: 1000}, function () {
                                $('#table').bootstrapTable('refresh');
                            });
                        } else {
                            layer.alert(res.message);
                        }
                    }
                })
            })
        }
    }

    // </editor-fold>


</script>
{/block}